<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    {include file="common/css"}
</head>
<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form">
                <blockquote class="layui-elem-quote">每日动态掌握全球科技.</blockquote>
                <a href="javascript:;" menu-title="发布动态" class="pear-btn pear-btn-primary pear-btn-sm" to lay-submit lay-filter="dynamic-add"><i class="layui-icon layui-icon-addition"></i>
                    动一动</a>
                <hr class="layui-border-blue">
                
                <div class="layui-form-item layui-inline">
                    
                    
                    <div class="layui-form-item layui-inline">
                        <label class="layui-form-label">发布内容</label>
                        <div class="layui-input-inline">
                            <input type="text" name="content" placeholder="" class="layui-input" autocomplete="off">
                        </div>
                    </div>
                    <div class="layui-form-item layui-inline">
                        <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                            <i class="layui-icon layui-icon-search"></i>
                            查询
                        </button>
                        <button type="reset" class="pear-btn pear-btn-md">
                            <i class="layui-icon layui-icon-refresh"></i>
                            重置
                        </button>
                    </div>
                    
                </div>
            </form>
        </div>
    </div>
    
    <div class="layui-card">
        <div class="layui-card-header">
            动 态
        </div>
        {empty name="dylist"}
        <div class="layui-table-body layui-table-main">
            <div class="layui-none">
                无数据
            </div>
        </div>
        {/empty}
        <div class="layui-card-body">
            <ul class="layui-timeline">
                {volist name="dylist" id="vo"}
                <li class="layui-timeline-item">
                    <i class="layui-icon layui-timeline-axis"></i>
                    <div class="layui-timeline-content layui-text">
                        <h3 class="layui-timeline-title">{$vo.create_time}
                            &nbsp;
                            <a href="javascript:;" style="text-decoration:none" lay-submit lay-filter="dynamic-edit" data-id="{$vo.id}"><i class="layui-icon layui-icon-edit"></i>
                            </a>
                            &nbsp;
                            <a href="javascript:;" style="text-decoration:none" lay-submit lay-filter="dynamic-remove" data-id="{$vo.id}"><i class="layui-icon layui-icon-delete"></i>
                            </a>
                        </h3>
                        
                        <p>
                            {$vo.content}
                        </p>
                    </div>
                </li>
                {/volist}
            </ul>
            <div>
                {$dylist|raw}
            </div>
        </div>
    </div>
    
{include file="common/js"}
<script>
    layui.use(['table', 'form', 'jquery','topBar','element','loading'], function() {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let element = layui.element;
        let loading = layui.loading;
        let MODULE_PATH = "{$Request.root}/admin.dynamic/";

        form.on('submit(dynamic-add)', function (obj) {
            layer.open({
                type: 2,
                title: '发布动态',
                shade: 0.1,
                area: ['100%', '100%'],
                content: MODULE_PATH + 'add'
            });
        });
        form.on('submit(dynamic-edit)', function () {
            let editid = $(this).attr('data-id');
            layer.open({
                type: 2,
                title: '发布动态',
                shade: 0.1,
                area: ['100%', '100%'],
                content: MODULE_PATH + 'edit/id/'+ editid
            });
        });
        // $("[to]").click(function(){
        //     top.layui.frame.changePageByElement("content",MODULE_PATH + 'add',"发布动态",true)
        // })
        form.on('submit(dynamic-remove)', function (obj) {
            let id = $(this).attr('data-id');
            layer.confirm('确定要删除该动态?', {
                icon: 3,
                title: '提示'
            }, function(index) {
                layer.close(index);
                // let loading = loading.Load(2,"");
                $.ajax({
                    url:MODULE_PATH + 'remove',
                    data:{id:id},
                    dataType: 'json',
                    type: 'POST',
                    success: function(res) {
                        // layer.close(loading.Load(5,""));
                        if (res.code==200) {
                            layer.msg(res.msg,{icon:1,time:1000},function(){
                                location.reload();
                            });
                        } else {
                            layer.msg(res.msg, {icon: 2,time: 1000});
                        }
                    }
                })
            });
        });

        form.on('submit(query)', function(data) {
            window.reload({ page: {curr: 1},where:data.field});
            // table.reload({ page: {curr: 1},where:data.field})
            return false;
        });
    })
</script>
</body>
</html>